import {
    ajaxPost,
    showToast
} from '../../../utils/util'

Page({

    /**
     * 页面的初始数据
     */
    data: {
        backShow: false, // 返回按钮
        companySource: {}, // 岗位详情
        workSource: {}, // 岗位详情
        collectVal: false, // 是否收藏
        sendVal: false, // 是否投递
        complaintShow: false, // 举报开关
        hidden: true,
        currentItem: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (options.type == 'share') {
            this.setData({
                backShow: true
            })
        }
        let data = {
            token: wx.getStorageSync('token'),
            position_id: options.workId
        }
        ajaxPost('/company/wxpositioninfo', data, res => {
            if (res.code == 0) {
                this.setData({
                    welfareSource: res.data.company_info.welfare,
                    companySource: res.data.company_info,
                    workSource: res.data,
                    collectVal: res.data.is_collection == 0 ? false : true,
                    sendVal: res.data.is_send == 0 ? false : true,
                    majorSource: res.data.major
                })
            }
        })
    },
    /**
     * 分享
     */
    onShareAppMessage() {
        return {
            title: `公司详情`,
            path: `/pages/share/share?identity=student&type=work&shareId=${this.data.workSource.id}`,
            success: function (res) {
                showToast('text', '分享成功')
            }
        }
    },
    tdjl() {
        if (this.data.sendVal) {
            showToast('text', '您已经投递过了');
            return;
        }
        let data = {
            token: wx.getStorageSync('token'),
            position_id: this.data.workSource.id
        }
        ajaxPost('/authuser/xxsendresume', data, res => {
            if (res.code == 0) {
                this.setData({
                    sendVal: true,
                })
                wx.navigateTo({
                    url: `/pages/student/sendSucceed/sendSucceed?id=${this.data.workSource.id}`
                });
            }
            if (res.code == 40002) {
                wx.showModal({
                    title: '操作提示',
                    content: '简历还没有完善，请完善简历后重试',
                    success(res) {
                        if (res.confirm) {
                            wx.navigateTo({
                                url: '/pages/student/mine/mine'
                            })
                        } else if (res.cancel) {
                            console.log('用户点击取消')
                        }
                    }
                })
            }
        });
        return;
    },
    /**
     * 收藏处理
     */
    collectClick() {
        let data = {
            token: wx.getStorageSync('token'),
            position_id: this.data.workSource.id
        }
        ajaxPost('/authuser/collectionposition', data, res => {
            if (res.code == 0) {
                if (this.data.collectVal) {
                    showToast('text', '取消收藏成功')
                } else {
                    showToast('text', '收藏成功')
                }
                this.setData({
                    collectVal: !this.data.collectVal
                })
            }
        })
    },
    /**
     * 举报控制
     */
    complaintClick() {
        this.setData({
            complaintShow: true
        })
    },
})